
import arxiv
import fitz  # PyMuPDF

def process_paper(query: str):
    # 搜索最新1篇相关论文
    search = arxiv.Search(
        query=query,
        max_results=1,
        sort_by=arxiv.SortCriterion.SubmittedDate
    )
    result = next(search.results())
    
    # 下载PDF并提取文本
    pdf_path = result.download_pdf()
    with fitz.open(pdf_path) as doc:
        text = "\n".join(page.get_text() for page in doc)
    
    return {
        "title": result.title,
        "authors": [str(a) for a in result.authors],
        "abstract": result.summary,
        "text_sample": text[:500] + "..."
    }
rs=process_paper("how to find page")
print(rs)